package 第2节数组;

public class LianXi05 {
    public static void main(String[] args) {
        int[] arr = {1,2,3,4,5,6,7,8,1};
        int sum = 0;
        for (int i = 0; i < arr.length; i++) {
            sum += arr[i];
        }
        if (sum % 3 != 0) {
            System.out.println("不能分");
            return; //结束函数
        }
        int key = sum / 3;

        //左区间和
        int leftSum = 0;
        int left = 0;
        //右区间和
        int rightSum = 0;
        int right = arr.length - 1;

        while (left < arr.length) {
            leftSum += arr[left];
            if (leftSum == key) {
                break;
            }
            left++;
        }
        while (right >= 0) {
            rightSum += arr[right];
            if (rightSum == key) {
                break;
            }
            right--;
        }
        if (left + 1 < right) {
            System.out.println("可以");
        } else {
            System.out.println("不可以");
        }
    }
}